package org.example.result;


import org.example.menu.CodeMenu;

/**
 * 统一分装返回结果
 */
public class ResultData {

    /**
     * 状态码
     */
    private Long code;

    /**
     * 返回信息
     */
    private String msg;

    /**
     * 返回数据
     */
    private Object data;

    public ResultData() {
    }

    public ResultData(Long code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Long getCode() {
        return code;
    }

    public void setCode(Long code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    /**
     * 认证失败
     * @return
     */
    public static ResultData authFail() {
        ResultData resultData = new ResultData();
        resultData.setCode(CodeMenu.AUTHFAIL.getCode());
        resultData.setMsg(CodeMenu.AUTHFAIL.getMsg());
        resultData.setData(null);
        return resultData;
    }


    public static ResultData authFail(String msg) {
        ResultData resultData = new ResultData();
        resultData.setCode(CodeMenu.AUTHFAIL.getCode());
        resultData.setMsg(msg);
        resultData.setData(null);
        return resultData;
    }

    /**
     * 操作成功
     */
    public static ResultData success() {
        ResultData resultData = new ResultData();
        resultData.setCode(CodeMenu.SUCCESS.getCode());
        resultData.setMsg(CodeMenu.SUCCESS.getMsg());
        resultData.setData(null);
        return resultData;
    }

    public static ResultData success(String msg) {
        ResultData resultData = new ResultData();
        resultData.setCode(CodeMenu.SUCCESS.getCode());
        resultData.setMsg(msg);
        resultData.setData(null);
        return resultData;
    }

    public static ResultData success(Object data) {
        ResultData resultData = new ResultData();
        resultData.setCode(CodeMenu.SUCCESS.getCode());
        resultData.setMsg(CodeMenu.SUCCESS.getMsg());
        resultData.setData(data);
        return resultData;
    }


    public static ResultData success(String msg, Object data) {
        ResultData resultData = new ResultData();
        resultData.setCode(CodeMenu.SUCCESS.getCode());
        resultData.setMsg(msg);
        resultData.setData(data);
        return resultData;
    }

    /**
     * 操作失败
     */
    public static ResultData fail() {
        ResultData resultData = new ResultData();
        resultData.setCode(CodeMenu.FAIL.getCode());
        resultData.setMsg(CodeMenu.FAIL.getMsg());
        resultData.setData(null);
        return resultData;
    }

    public static ResultData fail(String msg) {
        ResultData resultData = new ResultData();
        resultData.setCode(CodeMenu.FAIL.getCode());
        resultData.setMsg(msg);
        resultData.setData(null);
        return resultData;
    }

    public static ResultData fail(Object data) {
        ResultData resultData = new ResultData();
        resultData.setCode(CodeMenu.FAIL.getCode());
        resultData.setMsg(CodeMenu.FAIL.getMsg());
        resultData.setData(data);
        return resultData;
    }

    public static ResultData fail(String msg, Object data) {
        ResultData resultData = new ResultData();
        resultData.setCode(CodeMenu.FAIL.getCode());
        resultData.setMsg(msg);
        resultData.setData(data);
        return resultData;
    }


}
